#!/usr/bin/env python
#-*- coding:utf-8 -*-
# Copyright (c) 2011-2012 Chanrithy Thim
#
# AUTHOR:
# Chanrithy Thim <12rithy@gmail.com>
#
# This file is part of Appshell
#
# Appshell is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# Appshell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with AptUrl; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

from xml.etree import ElementTree as ET

# Class for manifest file
class Manifest():
    def __init__(self, filename):
        self.filename = filename
        self.execs = []
        self.get_info()
        self.get_exec()

    # Get information from manifest file
    def get_info(self):
        xml = ET.parse(self.filename)
        root = xml.find("Profile")
        for element in root: 
            if element.tag == "Name":
                self.name = element.text
            elif element.tag == "Arch":
                self.arch = element.text
            elif element.tag == "Maintainer":
                self.maintainer = element.text
            elif element.tag == "Email":
                self.email = element.text
            elif element.tag == "Homepage":
                self.homepage = element.text
            elif element.tag == "Summary":
                self.summary = element.text
            elif element.tag == "Version":
                self.version = element.text
                self.release = element.attrib["release"]
        
    # Get Executable list
    def get_exec(self):
        xml = ET.parse(self.filename)
        root = xml.find("Executable")
        self.exec_main = root.attrib["main"]
        for element in root: 
            if element.tag == "file":
                self.execs.append(element.text)
                
    def print_info(self):
        print "Name: %s" % self.name
        print "Arch: %s" % self.arch
        print "Maintainer: %s" % self.maintainer
        print "Email: %s" % self.email
        print "Homepage: %s" % self.homepage
        print "Summary: %s" % self.summary
        print "Version: %s-r%s" % (self.version, self.release)
        
        print "Main exec: %s" % self.exec_main
        for s in self.execs:
            print "Exec: %s" % s            
            
